<?php
/**
 * User: hufeng
 * Date: 2017/7/7
 * Desc:
 */
error_reporting(0);
date_default_timezone_set('PRC');

$serv = new swoole_server("0.0.0.0", 8079);
$serv->set(array(
    'daemonize' => true //是否作为守护进程
));

define('BASEDIR',__DIR__);
require 'App/Common/Conf/const.php';
require 'vendor/autoload.php';
require 'SasPHP/SasTimer.php';


//监听连接进入事件
$serv->on('connect', function ($serv, $fd) {
    echo "Client: Connect.\n";
});

//监听数据接收事件
$serv->on('receive', function ($serv, $fd, $from_id, $data) {
    $serv->send($fd, "Server: ".$data);
});

//监听连接关闭事件
$serv->on('close', function ($serv, $fd) {
    echo "Client: Close.\n";
});

$serv->on('start', function($serv) {
    cli_set_process_title("sd_timer");
});

$serv->on('WorkerStart', function ($serv, $fd) {
    swoole_timer_tick(60000, function(){
        $res = SasPHP\SasTimer::start('Timer','revokeDelegate');
        echo $res."\n";
    });
});

//启动服务器
$serv->start();